package com.centriole.servicepaasuser.controller;
import com.centriole.common.utils.PaasResult;
import com.centriole.common.entity.PaasApp;
import com.centriole.common.entity.PaasUser;
import com.centriole.servicepaasuser.service.PaasUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/paas",produces = "application/json;charset=utf-8")
public class PaasUserController {

    @Autowired
    PaasUserService paasUserService;

    @RequestMapping({"/",""})
    public PaasResult listAllUsers(){
        return PaasResult.success( paasUserService.listAllPaasUsers() );
    }

    @RequestMapping("/app")
    public  List<PaasApp> listAllApps(){
       return paasUserService.listAllPaasApps();
    }

    @RequestMapping("/service")
    public PaasResult listAllServices(){
        return PaasResult.success( paasUserService.listAllPaasServices() );
    }

    @RequestMapping({"/reg"})
    public PaasResult register(PaasUser user){
        //check ...
        if ( paasUserService.addPaasUser(user) ){
            //do sth ...
            return PaasResult.success("注册成功");
        }
        return PaasResult.success("注册失败，请重试");
    }

    @RequestMapping("/r")
    public PaasResult listRAllUser(){
        return PaasResult.success( paasUserService.listRAllPaasUsers() );
    }

    @RequestMapping("/serviceR")
    public PaasResult listRAllService(){
        return PaasResult.success( paasUserService.listRAllPaasServices() );
    }

    @RequestMapping("/bind")
    public PaasResult bindUserAndService(String userId, String[] sids){
        return paasUserService.relateUserAndService(userId,sids)?PaasResult.success("添加成功"):PaasResult.fail("添加失败");
    }

}
